package org2.jogo.activities;

import org2.jogo.R;
import org2.jogo.Sound;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

public abstract class GameActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(getContentView());
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.barra_titulo);
        TextView txtTitulo = (TextView) findViewById(R.id.labelTitle);
        txtTitulo.setText("Quiz Game - " + getTitulo());
        if (getMusicaFundo() > 0)
            Sound.iniciaMusicaFundo(this, getMusicaFundo());
    }

    protected abstract int getContentView();

    protected abstract int getMusicaFundo();
    
    protected abstract String getTitulo();

    @Override
    public void onPause() {
        super.onPause();
        Sound.pausarTodosOsSons();
    }

    @Override
    public void onResume() {
        super.onResume();
        Sound.continuarTodosOsSons();
    }
    
    @SuppressWarnings("unchecked")
    protected <T extends View> T getViewConvertida(View convertView, Context ctx, int layoutId) {
        if (convertView == null) {
            LayoutInflater factory = LayoutInflater.from(ctx);
            return (T) factory.inflate(layoutId, null);
        } else
            return (T) convertView;
    }
}
